package com.jwell.panprovider.ui.activity

import android.os.Bundle
import com.jwell.panprovider.R
import android.content.Intent
import android.view.KeyEvent
import android.view.View
import android.widget.Toast
import com.jwell.driverapp.ui.base.BaseActivity
import com.jwell.panprovider.tools.ActivityManager
import com.jwell.panprovider.tools.DataModel
import kotlinx.android.synthetic.main.activity_main.*


class MainActivity : BaseActivity(), View.OnClickListener {


    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContentView(R.layout.activity_main)
        ActivityManager.getInstance().pushOneActivity(this)
        setTransportStatusBar()
        ll_codeScan.setOnClickListener(this)
        rl_1.setOnClickListener(this)
        rl_2.setOnClickListener(this)
        rl_3.setOnClickListener(this)
        text_exit.setOnClickListener(this)
        DataModel.getInstance().userName?.let {
            text_userName.text = "欢迎您," + it
        }
    }

    override fun onClick(v: View) {
        when (v.id) {
            R.id.text_exit -> {
                skipToLogin(true)
            }

            R.id.rl_1 -> {//运输计划
                val intent = Intent(this, TransportPlaneActivity::class.java)
                startActivity(intent)
            }
            R.id.rl_2 -> {//电子磅单查询
                val intent = Intent(this, ElectronicPoundActivity::class.java)
                startActivity(intent)
            }
            R.id.rl_3 -> {//运单列表
                val intent = Intent(this, WaybillListActivity::class.java)
                startActivity(intent)
            }
        }
    }

    override fun onKeyDown(keyCode: Int, event: KeyEvent?): Boolean {
        // 过滤按键动作，按返回键不退出程序，直接退到桌面
        if (event!!.action == KeyEvent.ACTION_DOWN && keyCode == KeyEvent.KEYCODE_BACK) {
            moveTaskToBack(true)//true对任何Activity都适用
            return true
        }
        return super.onKeyDown(keyCode, event)
    }
}
